package com.dsy.xiangcun_index.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dsy.tools.common.utils.QueryObj;
import com.dsy.tools.entity.TbCulture;
import com.dsy.xiangcun_index.service.ITbCultureService;
import com.dsy.xiangcun_index.service.ITbTouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dsy
 * @since 2023-03-10
 */
@Controller
@RequestMapping("/culture")
public class TbCultureController {
    @Autowired
    ITbCultureService cultureService;
    @Autowired
    ITbTouService touService;

    /**
     * 分页文学作品列表
     * @param m
     * @param page
     * @param limit
     * @param queryObj
     * @return
     */
    @RequestMapping("/getAllCulture")
    public String getAllCulture(Model m, @RequestParam(defaultValue = "1") long page, @RequestParam(defaultValue = "10") long limit, QueryObj queryObj, HttpSession session){

        QueryWrapper<QueryObj> wrapper = new QueryWrapper<>();

        wrapper.setEntity(queryObj);
        IPage<TbCulture> culturePage = cultureService.getAllCulture(page,limit,wrapper);
        m.addAttribute("culturePage",culturePage);
        m.addAttribute("page",page);
        m.addAttribute("queryObj",queryObj);
        return "/culture/culture-list";
    }
    /**
     * 根据作品Id查询
     * @param m
     * @param cultureId
     * @return
     */
    @RequestMapping("/getCultureById")
    public String getCultureById(Model m,Integer cultureId){
        TbCulture culture=cultureService.getCultureById(cultureId);
        m.addAttribute("culture",culture);
        return "/culture/culture-look";
    }

}
